
package redis;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import utils.BytesPackUtils;
import Log.FastExLog;
import Quotation.Quotation;

/** 
 * @author yanchuanfeng
 * @version 创建时间：2022年2月25日 下午8:34:03 
 *  
 */

public class QuotationToRedisService {
    private static final String charset = "UTF-8";
    public static QuotationToRedisService quotaRedisService = new QuotationToRedisService();
	private QuotationToRedisService() {
		
	}
	
	public static QuotationToRedisService getQuotationToRedisService(){
		return quotaRedisService;
	}
	
	public void WriteQuotationToRedis(Quotation quotation){
		try {
			byte[] chl = quotation.getStkId().getBytes(charset);
			QuotaManagerRedis.redisConnectInstance().lpush(chl, BytesPackUtils.objectToBytes(quotation));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			FastExLog.log(e);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			FastExLog.log(e);
		}
	}
	
	public Quotation readQuotationToRedis(String stkId){
		Quotation quotation = null;
		try {
			byte[] chl = stkId.getBytes(charset);
			byte[] bytes = QuotaManagerRedis.redisConnectInstance().lpop(chl);
			Object obj = BytesPackUtils.bytesToObject(bytes);
			quotation = (Quotation)obj;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			FastExLog.log(e);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			FastExLog.log(e);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.print("get redis content:" + quotation.toString());
		return quotation;
	}
	
	
}
